package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.NewsPage;
import cn.wolfcode.trip.base.query.TravelCommentQueryObject;
import cn.wolfcode.trip.base.service.INewsPageService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/news")
public class NewsPageController {

    @Autowired
    public INewsPageService newsPageService;

    /**
     * 获取所有日报
     * @param qo
     * @return
     */
    @GetMapping
    public PageInfo listNewsPage(@ModelAttribute("qo") TravelCommentQueryObject qo){
        //根据排序
        qo.setOrderBy("releaseTime DESC");
        return newsPageService.queryForApp(qo);
    }

    /**
     * 查询日报内容
     * @param id
     * @return
     */
    @GetMapping("/{id}/content")
    public NewsPage getCatalog(@PathVariable Long id){
        return newsPageService.selectByPrimaryKey(id);
    }

    /**
     * 查询头条日报,根据浏览量
     * @return
     */
    @GetMapping("/bigger")
    public NewsPage getBigger(){
        return newsPageService.selectBiggerNews();
    }



}
